package com.ryan.quartz;

import com.ryan.quartz.job.HelloQuartzJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author Rayn on 2017/10/2.
 * @email liuwei412552703@163.com.
 */
public class App {

    public static void main(String[] args) {

        try {
            // Grab the Scheduler instance from the Factory
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();



            // define the job and tie it to our HelloJob class
            JobDetail job = JobBuilder.newJob(HelloQuartzJob.class)
                    .withIdentity("job1", "group1")
                    .build();

            // Trigger the job to run now, and then repeat every 40 seconds
            Trigger trigger = TriggerBuilder.newTrigger()
                    .withIdentity("trigger1", "group1")
                    .startNow()
                    .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                            .withIntervalInSeconds(40)
                            .repeatForever())
                    .build();

            // Tell quartz to schedule the job using our trigger
            scheduler.scheduleJob(job, trigger);

            // and start it off
            scheduler.start();

//            scheduler.shutdown();

        } catch (SchedulerException se) {
            se.printStackTrace();
        }
    }
}
